package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.EventTagSO;

@Entity
@Table(name = "EVENT_TAG", uniqueConstraints = @UniqueConstraint(columnNames = { "TAG_ID", "EVENT_ID" }))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class EventTag extends AbstractBaseModel {
	
	private static final long serialVersionUID = 1L;
    
	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "TAG_ID", nullable = false)
    private Tag tag;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "EVENT_ID", nullable = false)
	private Event event;

	public Tag getTag() {
		return tag;
	}

	public void setTag(Tag tag) {
		this.tag = tag;
	}

	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	@Override
	public String toString() {
		return "EventTag [tag=" + tag + ", event=" + event + "]";
	}

	public EventTagSO convertToServiceObject() {
		EventTagSO so = (EventTagSO) convert(new EventTagSO());
		so.setEvent(this.event.convertToServiceObject());
		so.setTag(this.tag.convertToServiceObject());
		return so;
	}

	
}
